package com.ndp.fb.rdb.api;

import com.ndp.fb.rdb.model.ConnectionObject;
import com.ndp.fb.rdb.model.EntrustAccount;
import com.ndp.fb.rdb.model.adpublishcondition.AdPublishCondition;
import com.ndp.fb.rdb.model.adpublishcondition.AdPublishConditionAccount;
import com.ndp.fb.rdb.model.adpublishcondition.AdPublishConditionDetail;
import com.ndp.fb.rdb.model.adpublishcondition.AdPublishConditionResult;
import com.ndp.fb.rdb.model.adpublishcondition.RegionAndPrice;
import com.ndp.fb.rdb.model.adpublishcondition.RegionAndPriceExt;
import com.ndp.fb.rdb.model.adpublishcondition.UserConnectionPage;

import java.util.Date;
import java.util.List;

/**
 * Created by Evan on 2015/3/23.
 */
public interface AdPublishConditionRdbService {

    /**
     * 条件主表保存
     */
    Long saveAdPublishCondition(AdPublishCondition o);

    /**
     * 条件 detail表 保存
     */
    void saveAdPublishConditionDetail(AdPublishConditionDetail detail);


    void updateTimeById(Long id, Date updateTime, Long updateUtcTime);

    /**
     * 分页查询投放控制
     * @param userId userId
     * @param key4Name 查询name 的关键字
     * @param orgId orgId
     * @return
     */
    List<AdPublishConditionResult> findAdPublishConditionWithPager(String  userId, String key4Name, Long orgId);

    /**
     * 按 应用和配置 查找 条件设置
     */
    AdPublishCondition findAdPublishCondition(String userId, Long connObjId, Long prodCfgId);
    /**
     * 按 应用和配置 查找 条件设置
     */
    AdPublishCondition findAdPublishCondition(String userId, Long connObjId, String platform);

    /**
     * 更新投放状态
     */
    void updateStatus(String userId, Long id, Boolean status);

    /**
     * 按 id 查找主表
     */
    AdPublishCondition findById(Long id);


    /**
     * 根据平台获取产品配置
     * @param userId
     * @param connObjId
     * @param platform
     * @return
     */
    AdPublishConditionDetail findDetailByConnObjIdPlatForm(String userId, Long connObjId, String platform);

    List<AdPublishConditionAccount> findAdPublishConditionAccount(Long conditionId,Long fbUserId);

    List<EntrustAccount> findAllowedAccounts(String userId, Long connObjId, Long prodCfgId);

    List<RegionAndPrice> findRegionAndPrice(Long conditionId);

    /**
     * 更新详情信息
     */
    void updateDetail(AdPublishConditionDetail detail);

    /**
     * 更新地区和出价
     */
    void updateRegionAndPrice(List<RegionAndPrice> regionAndPrices, Long conditionId);


    /**
     * 保存地区和出价
     */
    void batchSaveRegionAndPrice(List<RegionAndPrice> regionAndPrices, Long conditionId);

    /**
     * 更新账号支持CPA
     */
    void updateAccount(List<AdPublishConditionAccount> accounts, Long conditionId);

    /**
     * 保存账号是否支持CPA
     */
    void batchSaveAccount(List<AdPublishConditionAccount> accounts, Long conditionId);

    /**
     * 查找 应用 - 配置 -账户 是否支持CPA
     */

    List<ConnectionObject> findByTypeAndUserId(int type,String userId);


    List<RegionAndPriceExt> findAllRegionAndPricesByAppIds(String ticket, List<String> strings);



    /**
     * 查找当下打开的外链产品
     */
    List<AdPublishCondition> findOpenedOutlinkByUserIdAndOrgId(String userId, Long orgId);

    List<AdPublishCondition> findAll();

    List<AdPublishConditionAccount> findAdPublishConditionAccountByConditionId(Long conditionId);

    List<AdPublishCondition> findByIds( List<Long> ids);

    List<UserConnectionPage> findPageIdsByUserId(String userId);

}
